package cn.wen.yinxiu.works.service.impl;

import cn.wen.yinxiu.common.enums.DelEnum;
import cn.wen.yinxiu.common.enums.StatusEnum;
import cn.wen.yinxiu.works.dao.VisitHistoryDao;
import cn.wen.yinxiu.works.entity.VisitHistoryEntity;
import cn.wen.yinxiu.works.recommend.UserTopic;
import cn.wen.yinxiu.works.service.VisitHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.wen.yinxiu.common.toolkit.PageUtils;
import cn.wen.yinxiu.common.toolkit.Query;


@Service("visitHistoryService")
public class VisitHistoryServiceImpl extends ServiceImpl<VisitHistoryDao, VisitHistoryEntity> implements VisitHistoryService {

    @Autowired
    private VisitHistoryDao visitHistoryDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<VisitHistoryEntity> page = this.page(
                new Query<VisitHistoryEntity>().getPage(params),
                new QueryWrapper<VisitHistoryEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public Long queryUserVisitHistoryCount(Long userId) {
        QueryWrapper<VisitHistoryEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        queryWrapper.eq("status", StatusEnum.NORMAL_USE.code());
        queryWrapper.eq("is_deleted", DelEnum.NORMAL.code());
        return visitHistoryDao.selectCount(queryWrapper);
    }

    @Override
    public boolean deleteWorksVisitHistory(Long userId) {
        return visitHistoryDao.updateWorksVisitHistory(userId, DelEnum.DELETE.code());
    }

    @Override
    public List<UserTopic> queryUserVisitTopicByDate(Long userId, String pastDate) {
        return visitHistoryDao.queryUserVisitTopicByDate(userId, pastDate, StatusEnum.NORMAL_USE.code(),
                DelEnum.NORMAL.code());
    }

}